package cn.edu.sdjzu.xg.eagle.controller;

import cn.edu.sdjzu.xg.eagle.entities.Statistics;
import cn.edu.sdjzu.xg.eagle.service.impl.StatisticsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.List;

@RestController
@RequestMapping("statistics")
public class StatisticsController {

    @Autowired
    private StatisticsServiceImpl statisticsService;

    @PostMapping
    public String addStatistic(@RequestBody Statistics statistic) throws SQLException {
        return statisticsService.addStatistic(statistic);
    }

    @DeleteMapping("/{statisticId}")
    public String deleteStatistic(@PathVariable int statisticId) throws SQLException {
        return statisticsService.deleteStatistic(statisticId);
    }

    @PutMapping
    public String updateStatistic(@RequestBody Statistics statistic) throws SQLException {
        return statisticsService.updateStatistic(statistic);
    }

    @GetMapping("/{statisticId}")
    public Statistics getStatistic(@PathVariable int statisticId) throws SQLException {
        return statisticsService.findStatisticById(statisticId);
    }

    @GetMapping
    public List<Statistics> getAllStatistics() throws SQLException {
        return statisticsService.findAllStatistics();
    }
}